package leetcode.code1996;

import java.util.Arrays;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;

public class Solution implements IDebug {

	public int numberOfWeakCharacters(int[][] properties) {
		Arrays.sort(properties, (a, d) -> a[0] == d[0] ? a[1] - d[1] : d[0] - a[0]);
//		H.printObject(properties);
		int ans = 0;
		int maxd = properties[0][1];
		for (int i = 1; i < properties.length; i++) {
			int curd = properties[i][1];
			if (curd < maxd) {
				ans += 1;
			}
			maxd = Math.max(maxd, curd);
		}
		return ans;
	}

	@Override
	public void debug1() {
		HelpDebug.compare(1, this.numberOfWeakCharacters(HelpDebug.str2array1("[[1,1],[2,1],[2,2],[1,2]]")));

	}

	@Override
	public void debug2() {
		HelpDebug.compare(0, this.numberOfWeakCharacters(HelpDebug.str2array1("[[5,5],[6,3],[3,6]]")));

	}

	@Override
	public void debug3() {
		HelpDebug.compare(1, this.numberOfWeakCharacters(HelpDebug.str2array1("[[2,2],[3,3]]")));

	}

	@Override
	public void debug4() {
		HelpDebug.compare(1, this.numberOfWeakCharacters(HelpDebug.str2array1("[[1,5],[10,4],[4,3]]")));

	}

	public void debug5() {
		HelpDebug.compare(6, this.numberOfWeakCharacters(
				HelpDebug.str2array1("[[7,7],[1,2],[9,7],[7,3],[3,10],[9,8],[8,10],[4,3],[1,5],[1,5]]")));

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();
		so.debug5();

	}

}
